"""Definition of the Comix Page content type
"""

from zope.interface import implements

from Products.Archetypes import atapi
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata
from Products.ATContentTypes.configuration import zconf
from Products.ePub import ePubMessageFactory as _
from Products.ePub.config import PROJECTNAME
from Products.ePub.interfaces import IHobby

from Products.validation.config import validation
from Products.validation.validators.SupplValidators import MaxSizeValidator
from Products.validation import V_REQUIRED

validation.register(MaxSizeValidator('checkImageMaxSize',
                                     maxsize=zconf.ATImage.max_file_size))

HobbySchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-
    atapi.ImageField('photo',
                    required=True,
#                    primary=True,
                    languageIndependent=True,
#                    storage = atapi.AnnotationStorage(migrate=True),
                    swallowResizeExceptions = zconf.swallowImageResizeExceptions.enable,
                    pil_quality = zconf.pil_config.quality,
                    pil_resize_algo = zconf.pil_config.resize_algo,
                    max_size = zconf.ATImage.max_image_dimension,
                    sizes= {
                            'preview' : (400, 400),
                            'mini'    : (200, 200),
                    },
                    validators = (('isNonEmptyFile', V_REQUIRED),
                                  ('checkImageMaxSize', V_REQUIRED)),
                    widget = atapi.ImageWidget(
                        label = _(u'label_info_hobbyphoto',default = u'Photo'),
                        description = _(u'help_info_hobbyphoto',default=u'')
                    )                   
    ),
    
    atapi.FloatField('price',
                    required = False,
                    widget = atapi.StringWidget(
                        label=_(u'label_info_price',default=u'Price'),
                        description = _(u'help_info_price',default=u'')
                    )
    ),

))

# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.


schemata.finalizeATCTSchema(HobbySchema, moveDiscussion=False)


class Hobby(base.ATCTContent):
    
    portal_type    = 'Hobby'
    archetype_name = 'Hobby'
        
    meta_type = "Hobby"
    schema = HobbySchema

    implements(IHobby)

atapi.registerType(Hobby, PROJECTNAME)
